package threadTest;

import java.util.concurrent.locks.LockSupport;

/**
 * @Version: sync_wait_notify_version_LockSupport
 * @Description:02版本的第二种写法 利用工具类LockSupport
 * @LastDate:2020年9月27日上午11:15:57
 */
public class ThreadTest04_LockSupport {
	public static Thread t1 = null, t2 = null;
	public static void main(String[] args) {
		char[] a1 = "123456".toCharArray();
		char[] a2 = "ABCDEF".toCharArray();
		
		t1 = new Thread(()->{

				for (var c : a1) {
					LockSupport.park();//阻塞
					System.out.print(c);
					LockSupport.unpark(t2);//唤醒
				}
				
		}, "t1");
		
		t2 = new Thread(()->{

				for (var c : a2) {
					System.out.print(c);
					LockSupport.unpark(t1);//应该先唤醒别人 再锁住自己 要不然叫不醒别人
					LockSupport.park();
				}

		}, "t2");
		
		t1.start();
		t2.start();
	}
}
